


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > LinkedMultiTreeNode</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/highlight-idea.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.pack.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">net.mooctest</a>
</div>

<h1>Coverage Summary for Class: LinkedMultiTreeNode (net.mooctest)</h1>

<table class="coverageStats">

<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">LinkedMultiTreeNode</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/14)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/118)
  </span>
</td>
</tr>
  <tr>
    <td class="name">LinkedMultiTreeNode$1</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/3)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/3)
  </span>
</td>
  </tr>
<tr>
  <td class="name"><strong>Total</strong></td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/17)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/121)
  </span>
</td>
</tr>
</table>

<br/>
<br/>


<pre>
<div class="sourceCode" id="sourceCode"><i class="no-highlight">1</i>&nbsp;package net.mooctest;
<i class="no-highlight">2</i>&nbsp;
<i class="no-highlight">3</i>&nbsp;
<i class="no-highlight">4</i>&nbsp;import java.util.Collection;
<i class="no-highlight">5</i>&nbsp;import java.util.Collections;
<i class="no-highlight">6</i>&nbsp;import java.util.LinkedHashSet;
<i class="no-highlight">7</i>&nbsp;
<i class="no-highlight">8</i>&nbsp;/**
<i class="no-highlight">9</i>&nbsp; * Implementation of the K-ary (multi node) tree data structure,
<i class="no-highlight">10</i>&nbsp; * based on the leftmost-child-right-sibling representation
<i class="no-highlight">11</i>&nbsp; *
<i class="no-highlight">12</i>&nbsp; * @author shell
<i class="no-highlight">13</i>&nbsp; * @version 1.0.0
<i class="no-highlight">14</i>&nbsp; * @since 1.0.0
<i class="no-highlight">15</i>&nbsp; */
<i class="no-highlight">16</i>&nbsp;public class LinkedMultiTreeNode&lt;T&gt; extends MultiTreeNode&lt;T&gt; {
<i class="no-highlight">17</i>&nbsp;
<i class="no-highlight">18</i>&nbsp;	/**
<i class="no-highlight">19</i>&nbsp;	 * Current UID of this object used for serialization
<i class="no-highlight">20</i>&nbsp;	 */
<i class="no-highlight">21</i>&nbsp;	private static final long serialVersionUID = 1L;
<i class="no-highlight">22</i>&nbsp;
<i class="no-highlight">23</i>&nbsp;	/**
<i class="no-highlight">24</i>&nbsp;	 * A reference to the first subtree tree node of the current tree node
<i class="no-highlight">25</i>&nbsp;	 */
<i class="no-highlight">26</i>&nbsp;	private LinkedMultiTreeNode&lt;T&gt; leftMostNode;
<i class="no-highlight">27</i>&nbsp;
<i class="no-highlight">28</i>&nbsp;	/**
<i class="no-highlight">29</i>&nbsp;	 * A reference to the right sibling tree node of the current tree node
<i class="no-highlight">30</i>&nbsp;	 */
<i class="no-highlight">31</i>&nbsp;	private LinkedMultiTreeNode&lt;T&gt; rightSiblingNode;
<i class="no-highlight">32</i>&nbsp;
<i class="no-highlight">33</i>&nbsp;	/**
<i class="no-highlight">34</i>&nbsp;	 * A reference to the last subtree node of the current tree node
<i class="no-highlight">35</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">36</i>&nbsp;	 * Used to avoid the discovery of the last subtree node. As a result
<i class="no-highlight">37</i>&nbsp;	 * significantly optimized such operations like addition etc.
<i class="no-highlight">38</i>&nbsp;	 */
<i class="no-highlight">39</i>&nbsp;	private LinkedMultiTreeNode&lt;T&gt; lastSubtreeNode;
<i class="no-highlight">40</i>&nbsp;
<i class="no-highlight">41</i>&nbsp;	/**
<i class="no-highlight">42</i>&nbsp;	 * Creates an instance of this class
<i class="no-highlight">43</i>&nbsp;	 *
<i class="no-highlight">44</i>&nbsp;	 * @param data data to store in the current tree node
<i class="no-highlight">45</i>&nbsp;	 */
<i class="no-highlight">46</i>&nbsp;	public LinkedMultiTreeNode(T data) {
<b class="nc"><i class="no-highlight">47</i>&nbsp;		super(data);</b>
<i class="no-highlight">48</i>&nbsp;	}
<i class="no-highlight">49</i>&nbsp;
<i class="no-highlight">50</i>&nbsp;	/**
<i class="no-highlight">51</i>&nbsp;	 * Returns the collection of the child nodes of the current node
<i class="no-highlight">52</i>&nbsp;	 * with all of its proper descendants, if any
<i class="no-highlight">53</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">54</i>&nbsp;	 * Returns {@link Collections#emptySet()} if the current node is leaf
<i class="no-highlight">55</i>&nbsp;	 *
<i class="no-highlight">56</i>&nbsp;	 * @return collection of the child nodes of the current node with
<i class="no-highlight">57</i>&nbsp;	 *         all of its proper descendants, if any;
<i class="no-highlight">58</i>&nbsp;	 *         {@link Collections#emptySet()} if the current node is leaf
<i class="no-highlight">59</i>&nbsp;	 */
<i class="no-highlight">60</i>&nbsp;	@Override
<i class="no-highlight">61</i>&nbsp;	public Collection&lt;? extends TreeNode&lt;T&gt;&gt; subtrees() {
<b class="nc"><i class="no-highlight">62</i>&nbsp;		if (isLeaf()) {</b>
<b class="nc"><i class="no-highlight">63</i>&nbsp;			return Collections.emptySet();</b>
<i class="no-highlight">64</i>&nbsp;		}
<b class="nc"><i class="no-highlight">65</i>&nbsp;		Collection&lt;TreeNode&lt;T&gt;&gt; subtrees = new LinkedHashSet&lt;&gt;();</b>
<b class="nc"><i class="no-highlight">66</i>&nbsp;		subtrees.add(leftMostNode);</b>
<b class="nc"><i class="no-highlight">67</i>&nbsp;		LinkedMultiTreeNode&lt;T&gt; nextSubtree = leftMostNode.rightSiblingNode;</b>
<b class="nc"><i class="no-highlight">68</i>&nbsp;		while (nextSubtree != null) {</b>
<b class="nc"><i class="no-highlight">69</i>&nbsp;			subtrees.add(nextSubtree);</b>
<b class="nc"><i class="no-highlight">70</i>&nbsp;			nextSubtree = nextSubtree.rightSiblingNode;</b>
<i class="no-highlight">71</i>&nbsp;		}
<b class="nc"><i class="no-highlight">72</i>&nbsp;		return subtrees;</b>
<i class="no-highlight">73</i>&nbsp;	}
<i class="no-highlight">74</i>&nbsp;
<i class="no-highlight">75</i>&nbsp;	/**
<i class="no-highlight">76</i>&nbsp;	 * Adds the subtree with all of its descendants to the current tree node
<i class="no-highlight">77</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">78</i>&nbsp;	 * {@code null} subtree cannot be added, in this case return result will
<i class="no-highlight">79</i>&nbsp;	 * be {@code false}
<i class="no-highlight">80</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">81</i>&nbsp;	 * Checks whether this tree node was changed as a result of the call
<i class="no-highlight">82</i>&nbsp;	 *
<i class="no-highlight">83</i>&nbsp;	 * @param subtree subtree to add to the current tree node
<i class="no-highlight">84</i>&nbsp;	 * @return {@code true} if this tree node was changed as a
<i class="no-highlight">85</i>&nbsp;	 *         result of the call; {@code false} otherwise
<i class="no-highlight">86</i>&nbsp;	 */
<i class="no-highlight">87</i>&nbsp;	@Override
<i class="no-highlight">88</i>&nbsp;	public boolean add(TreeNode&lt;T&gt; subtree) {
<b class="nc"><i class="no-highlight">89</i>&nbsp;		if (subtree == null) {</b>
<b class="nc"><i class="no-highlight">90</i>&nbsp;			return false;</b>
<i class="no-highlight">91</i>&nbsp;		}
<b class="nc"><i class="no-highlight">92</i>&nbsp;		linkParent(subtree, this);</b>
<b class="nc"><i class="no-highlight">93</i>&nbsp;		if (isLeaf()) {</b>
<b class="nc"><i class="no-highlight">94</i>&nbsp;			leftMostNode = (LinkedMultiTreeNode&lt;T&gt;) subtree;</b>
<b class="nc"><i class="no-highlight">95</i>&nbsp;			lastSubtreeNode = leftMostNode;</b>
<i class="no-highlight">96</i>&nbsp;		} else {
<b class="nc"><i class="no-highlight">97</i>&nbsp;			lastSubtreeNode.rightSiblingNode = (LinkedMultiTreeNode&lt;T&gt;) subtree;</b>
<b class="nc"><i class="no-highlight">98</i>&nbsp;			lastSubtreeNode = lastSubtreeNode.rightSiblingNode;</b>
<i class="no-highlight">99</i>&nbsp;		}
<b class="nc"><i class="no-highlight">100</i>&nbsp;		return true;</b>
<i class="no-highlight">101</i>&nbsp;	}
<i class="no-highlight">102</i>&nbsp;
<i class="no-highlight">103</i>&nbsp;	/**
<i class="no-highlight">104</i>&nbsp;	 * Drops the first occurrence of the specified subtree from the current
<i class="no-highlight">105</i>&nbsp;	 * tree node
<i class="no-highlight">106</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">107</i>&nbsp;	 * Checks whether the current tree node was changed as a result of
<i class="no-highlight">108</i>&nbsp;	 * the call
<i class="no-highlight">109</i>&nbsp;	 *
<i class="no-highlight">110</i>&nbsp;	 * @param subtree subtree to drop from the current tree node
<i class="no-highlight">111</i>&nbsp;	 * @return {@code true} if the current tree node was changed as a result
<i class="no-highlight">112</i>&nbsp;	 *         of the call; {@code false} otherwise
<i class="no-highlight">113</i>&nbsp;	 */
<i class="no-highlight">114</i>&nbsp;	@Override
<i class="no-highlight">115</i>&nbsp;	public boolean dropSubtree(TreeNode&lt;T&gt; subtree) {
<b class="nc"><i class="no-highlight">116</i>&nbsp;		if (subtree == null</b>
<b class="nc"><i class="no-highlight">117</i>&nbsp;				|| isLeaf()</b>
<b class="nc"><i class="no-highlight">118</i>&nbsp;				|| subtree.isRoot()) {</b>
<b class="nc"><i class="no-highlight">119</i>&nbsp;			return false;</b>
<i class="no-highlight">120</i>&nbsp;		}
<b class="nc"><i class="no-highlight">121</i>&nbsp;		if (leftMostNode.equals(subtree)) {</b>
<b class="nc"><i class="no-highlight">122</i>&nbsp;			leftMostNode = leftMostNode.rightSiblingNode;</b>
<b class="nc"><i class="no-highlight">123</i>&nbsp;			unlinkParent(subtree);</b>
<b class="nc"><i class="no-highlight">124</i>&nbsp;			((LinkedMultiTreeNode&lt;T&gt;) subtree).rightSiblingNode = null;</b>
<b class="nc"><i class="no-highlight">125</i>&nbsp;			return true;</b>
<i class="no-highlight">126</i>&nbsp;		} else {
<b class="nc"><i class="no-highlight">127</i>&nbsp;			LinkedMultiTreeNode&lt;T&gt; nextSubtree = leftMostNode;</b>
<b class="nc"><i class="no-highlight">128</i>&nbsp;			while (nextSubtree.rightSiblingNode != null) {</b>
<b class="nc"><i class="no-highlight">129</i>&nbsp;				if (nextSubtree.rightSiblingNode.equals(subtree)) {</b>
<b class="nc"><i class="no-highlight">130</i>&nbsp;					unlinkParent(subtree);</b>
<b class="nc"><i class="no-highlight">131</i>&nbsp;					nextSubtree.rightSiblingNode = nextSubtree.rightSiblingNode.rightSiblingNode;</b>
<b class="nc"><i class="no-highlight">132</i>&nbsp;					((LinkedMultiTreeNode&lt;T&gt;) subtree).rightSiblingNode = null;</b>
<b class="nc"><i class="no-highlight">133</i>&nbsp;					return true;</b>
<i class="no-highlight">134</i>&nbsp;				} else {
<b class="nc"><i class="no-highlight">135</i>&nbsp;					nextSubtree = nextSubtree.rightSiblingNode;</b>
<i class="no-highlight">136</i>&nbsp;				}
<i class="no-highlight">137</i>&nbsp;			}
<i class="no-highlight">138</i>&nbsp;		}
<b class="nc"><i class="no-highlight">139</i>&nbsp;		return false;</b>
<i class="no-highlight">140</i>&nbsp;	}
<i class="no-highlight">141</i>&nbsp;
<i class="no-highlight">142</i>&nbsp;	/**
<i class="no-highlight">143</i>&nbsp;	 * Removes all the subtrees with all of its descendants from the current
<i class="no-highlight">144</i>&nbsp;	 * tree node
<i class="no-highlight">145</i>&nbsp;	 */
<i class="no-highlight">146</i>&nbsp;	@Override
<i class="no-highlight">147</i>&nbsp;	public void clear() {
<b class="nc"><i class="no-highlight">148</i>&nbsp;		if (!isLeaf()) {</b>
<b class="nc"><i class="no-highlight">149</i>&nbsp;			LinkedMultiTreeNode&lt;T&gt; nextNode = leftMostNode;</b>
<b class="nc"><i class="no-highlight">150</i>&nbsp;			while (nextNode != null) {</b>
<b class="nc"><i class="no-highlight">151</i>&nbsp;				unlinkParent(nextNode);</b>
<b class="nc"><i class="no-highlight">152</i>&nbsp;				LinkedMultiTreeNode&lt;T&gt; nextNodeRightSiblingNode = nextNode.rightSiblingNode;</b>
<b class="nc"><i class="no-highlight">153</i>&nbsp;				nextNode.rightSiblingNode = null;</b>
<b class="nc"><i class="no-highlight">154</i>&nbsp;				nextNode.lastSubtreeNode = null;</b>
<b class="nc"><i class="no-highlight">155</i>&nbsp;				nextNode = nextNodeRightSiblingNode;</b>
<b class="nc"><i class="no-highlight">156</i>&nbsp;			}</b>
<b class="nc"><i class="no-highlight">157</i>&nbsp;			leftMostNode = null;</b>
<i class="no-highlight">158</i>&nbsp;		}
<i class="no-highlight">159</i>&nbsp;	}
<i class="no-highlight">160</i>&nbsp;
<i class="no-highlight">161</i>&nbsp;	/**
<i class="no-highlight">162</i>&nbsp;	 * Returns an iterator over the elements in this tree in proper sequence
<i class="no-highlight">163</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">164</i>&nbsp;	 * The returned iterator is &lt;b&gt;fail-fast&lt;/b&gt;
<i class="no-highlight">165</i>&nbsp;	 *
<i class="no-highlight">166</i>&nbsp;	 * @return an iterator over the elements in this tree in proper sequence
<i class="no-highlight">167</i>&nbsp;	 */
<i class="no-highlight">168</i>&nbsp;	@Override
<i class="no-highlight">169</i>&nbsp;	public TreeNodeIterator iterator() {
<b class="nc"><i class="no-highlight">170</i>&nbsp;		return new TreeNodeIterator() {</b>
<i class="no-highlight">171</i>&nbsp;
<i class="no-highlight">172</i>&nbsp;			/**
<i class="no-highlight">173</i>&nbsp;			 * Returns the leftmost node of the current tree node if the
<i class="no-highlight">174</i>&nbsp;			 * current tree node is not a leaf
<i class="no-highlight">175</i>&nbsp;			 *
<i class="no-highlight">176</i>&nbsp;			 * @return leftmost node of the current tree node if the current
<i class="no-highlight">177</i>&nbsp;			 *         tree node is not a leaf
<i class="no-highlight">178</i>&nbsp;			 * @throws TreeNodeException an exception that is thrown in case
<i class="no-highlight">179</i>&nbsp;			 *                           if the current tree node is a leaf
<i class="no-highlight">180</i>&nbsp;			 */
<i class="no-highlight">181</i>&nbsp;			@Override
<i class="no-highlight">182</i>&nbsp;			protected TreeNode&lt;T&gt; leftMostNode() {
<b class="nc"><i class="no-highlight">183</i>&nbsp;				return leftMostNode;</b>
<i class="no-highlight">184</i>&nbsp;			}
<i class="no-highlight">185</i>&nbsp;
<i class="no-highlight">186</i>&nbsp;			/**
<i class="no-highlight">187</i>&nbsp;			 * Returns the right sibling node of the current tree node if the
<i class="no-highlight">188</i>&nbsp;			 * current tree node is not root
<i class="no-highlight">189</i>&nbsp;			 *
<i class="no-highlight">190</i>&nbsp;			 * @return right sibling node of the current tree node if the current
<i class="no-highlight">191</i>&nbsp;			 *         tree node is not root
<i class="no-highlight">192</i>&nbsp;			 * @throws TreeNodeException an exception that may be thrown in case if
<i class="no-highlight">193</i>&nbsp;			 *                           the current tree node is root
<i class="no-highlight">194</i>&nbsp;			 */
<i class="no-highlight">195</i>&nbsp;			@Override
<i class="no-highlight">196</i>&nbsp;			protected TreeNode&lt;T&gt; rightSiblingNode() {
<b class="nc"><i class="no-highlight">197</i>&nbsp;				return rightSiblingNode;</b>
<i class="no-highlight">198</i>&nbsp;			}
<i class="no-highlight">199</i>&nbsp;
<i class="no-highlight">200</i>&nbsp;		};
<i class="no-highlight">201</i>&nbsp;	}
<i class="no-highlight">202</i>&nbsp;
<i class="no-highlight">203</i>&nbsp;	/**
<i class="no-highlight">204</i>&nbsp;	 * Checks whether the current tree node is a leaf, e.g. does not have any
<i class="no-highlight">205</i>&nbsp;	 * subtrees
<i class="no-highlight">206</i>&nbsp;	 *
<i class="no-highlight">207</i>&nbsp;	 * @return {@code true} if the current tree node is a leaf, e.g. does not
<i class="no-highlight">208</i>&nbsp;	 *         have any subtrees; {@code false} otherwise
<i class="no-highlight">209</i>&nbsp;	 */
<i class="no-highlight">210</i>&nbsp;	@Override
<i class="no-highlight">211</i>&nbsp;	public boolean isLeaf() {
<b class="nc"><i class="no-highlight">212</i>&nbsp;		return leftMostNode == null;</b>
<i class="no-highlight">213</i>&nbsp;	}
<i class="no-highlight">214</i>&nbsp;
<i class="no-highlight">215</i>&nbsp;	/**
<i class="no-highlight">216</i>&nbsp;	 * Checks whether among the current tree node subtrees there is
<i class="no-highlight">217</i>&nbsp;	 * a specified subtree
<i class="no-highlight">218</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">219</i>&nbsp;	 * Overridden to have a faster array implementation
<i class="no-highlight">220</i>&nbsp;	 *
<i class="no-highlight">221</i>&nbsp;	 * @param subtree subtree whose presence within the current tree
<i class="no-highlight">222</i>&nbsp;	 *                node children is to be checked
<i class="no-highlight">223</i>&nbsp;	 * @return {@code true} if among the current tree node subtrees
<i class="no-highlight">224</i>&nbsp;	 *         there is a specified subtree; {@code false} otherwise
<i class="no-highlight">225</i>&nbsp;	 */
<i class="no-highlight">226</i>&nbsp;	@Override
<i class="no-highlight">227</i>&nbsp;	public boolean hasSubtree(TreeNode&lt;T&gt; subtree) {
<b class="nc"><i class="no-highlight">228</i>&nbsp;		if (subtree == null</b>
<b class="nc"><i class="no-highlight">229</i>&nbsp;				|| isLeaf()</b>
<b class="nc"><i class="no-highlight">230</i>&nbsp;				|| subtree.isRoot()) {</b>
<b class="nc"><i class="no-highlight">231</i>&nbsp;			return false;</b>
<i class="no-highlight">232</i>&nbsp;		}
<b class="nc"><i class="no-highlight">233</i>&nbsp;		LinkedMultiTreeNode&lt;T&gt; nextSubtree = leftMostNode;</b>
<b class="nc"><i class="no-highlight">234</i>&nbsp;		while (nextSubtree != null) {</b>
<b class="nc"><i class="no-highlight">235</i>&nbsp;			if (nextSubtree.equals(subtree)) {</b>
<b class="nc"><i class="no-highlight">236</i>&nbsp;				return true;</b>
<i class="no-highlight">237</i>&nbsp;			} else {
<b class="nc"><i class="no-highlight">238</i>&nbsp;				nextSubtree = nextSubtree.rightSiblingNode;</b>
<i class="no-highlight">239</i>&nbsp;			}
<i class="no-highlight">240</i>&nbsp;		}
<b class="nc"><i class="no-highlight">241</i>&nbsp;		return false;</b>
<i class="no-highlight">242</i>&nbsp;	}
<i class="no-highlight">243</i>&nbsp;
<i class="no-highlight">244</i>&nbsp;	/**
<i class="no-highlight">245</i>&nbsp;	 * Checks whether the current tree node with all of its descendants
<i class="no-highlight">246</i>&nbsp;	 * (entire tree) contains the specified node
<i class="no-highlight">247</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">248</i>&nbsp;	 * Overridden to have a faster array implementation
<i class="no-highlight">249</i>&nbsp;	 *
<i class="no-highlight">250</i>&nbsp;	 * @param node node whose presence within the current tree node with
<i class="no-highlight">251</i>&nbsp;	 *             all of its descendants (entire tree) is to be checked
<i class="no-highlight">252</i>&nbsp;	 * @return {@code true} if the current node with all of its descendants
<i class="no-highlight">253</i>&nbsp;	 *         (entire tree) contains the specified node; {@code false}
<i class="no-highlight">254</i>&nbsp;	 *         otherwise
<i class="no-highlight">255</i>&nbsp;	 */
<i class="no-highlight">256</i>&nbsp;	@Override
<i class="no-highlight">257</i>&nbsp;	public boolean contains(TreeNode&lt;T&gt; node) {
<b class="nc"><i class="no-highlight">258</i>&nbsp;		if (node == null</b>
<b class="nc"><i class="no-highlight">259</i>&nbsp;				|| isLeaf()</b>
<b class="nc"><i class="no-highlight">260</i>&nbsp;				|| node.isRoot()) {</b>
<b class="nc"><i class="no-highlight">261</i>&nbsp;			return false;</b>
<i class="no-highlight">262</i>&nbsp;		}
<b class="nc"><i class="no-highlight">263</i>&nbsp;		LinkedMultiTreeNode&lt;T&gt; nextSubtree = leftMostNode;</b>
<b class="nc"><i class="no-highlight">264</i>&nbsp;		while (nextSubtree != null) {</b>
<b class="nc"><i class="no-highlight">265</i>&nbsp;			if (nextSubtree.equals(node)) {</b>
<b class="nc"><i class="no-highlight">266</i>&nbsp;				return true;</b>
<i class="no-highlight">267</i>&nbsp;			}
<b class="nc"><i class="no-highlight">268</i>&nbsp;			if (nextSubtree.contains(node)) {</b>
<b class="nc"><i class="no-highlight">269</i>&nbsp;				return true;</b>
<i class="no-highlight">270</i>&nbsp;			}
<b class="nc"><i class="no-highlight">271</i>&nbsp;			nextSubtree = nextSubtree.rightSiblingNode;</b>
<i class="no-highlight">272</i>&nbsp;		}
<b class="nc"><i class="no-highlight">273</i>&nbsp;		return false;</b>
<i class="no-highlight">274</i>&nbsp;	}
<i class="no-highlight">275</i>&nbsp;
<i class="no-highlight">276</i>&nbsp;	/**
<i class="no-highlight">277</i>&nbsp;	 * Removes the first occurrence of the specified node from the entire tree,
<i class="no-highlight">278</i>&nbsp;	 * starting from the current tree node and traversing in a pre order manner
<i class="no-highlight">279</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">280</i>&nbsp;	 * Checks whether the current tree node was changed as a result of the call
<i class="no-highlight">281</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">282</i>&nbsp;	 * Overridden to have a faster array implementation
<i class="no-highlight">283</i>&nbsp;	 *
<i class="no-highlight">284</i>&nbsp;	 * @param node node to remove from the entire tree
<i class="no-highlight">285</i>&nbsp;	 * @return {@code true} if the current tree node was changed as a result of
<i class="no-highlight">286</i>&nbsp;	 *         the call; {@code false} otherwise
<i class="no-highlight">287</i>&nbsp;	 */
<i class="no-highlight">288</i>&nbsp;	@Override
<i class="no-highlight">289</i>&nbsp;	public boolean remove(TreeNode&lt;T&gt; node) {
<b class="nc"><i class="no-highlight">290</i>&nbsp;		if (node == null</b>
<b class="nc"><i class="no-highlight">291</i>&nbsp;				|| isLeaf()</b>
<b class="nc"><i class="no-highlight">292</i>&nbsp;				|| node.isRoot()) {</b>
<b class="nc"><i class="no-highlight">293</i>&nbsp;			return false;</b>
<i class="no-highlight">294</i>&nbsp;		}
<b class="nc"><i class="no-highlight">295</i>&nbsp;		if (dropSubtree(node)) {</b>
<b class="nc"><i class="no-highlight">296</i>&nbsp;			return true;</b>
<i class="no-highlight">297</i>&nbsp;		}
<b class="nc"><i class="no-highlight">298</i>&nbsp;		LinkedMultiTreeNode&lt;T&gt; nextSubtree = leftMostNode;</b>
<b class="nc"><i class="no-highlight">299</i>&nbsp;		while (nextSubtree != null) {</b>
<b class="nc"><i class="no-highlight">300</i>&nbsp;			if (nextSubtree.remove(node)) {</b>
<b class="nc"><i class="no-highlight">301</i>&nbsp;				return true;</b>
<i class="no-highlight">302</i>&nbsp;			}
<b class="nc"><i class="no-highlight">303</i>&nbsp;			nextSubtree = nextSubtree.rightSiblingNode;</b>
<i class="no-highlight">304</i>&nbsp;		}
<b class="nc"><i class="no-highlight">305</i>&nbsp;		return false;</b>
<i class="no-highlight">306</i>&nbsp;	}
<i class="no-highlight">307</i>&nbsp;
<i class="no-highlight">308</i>&nbsp;	/**
<i class="no-highlight">309</i>&nbsp;	 * Traverses the tree in a pre ordered manner starting from the
<i class="no-highlight">310</i>&nbsp;	 * current tree node and performs the traversal action on each
<i class="no-highlight">311</i>&nbsp;	 * traversed tree node
<i class="no-highlight">312</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">313</i>&nbsp;	 * Overridden to have a faster array implementation
<i class="no-highlight">314</i>&nbsp;	 *
<i class="no-highlight">315</i>&nbsp;	 * @param action action, which is to be performed on each tree
<i class="no-highlight">316</i>&nbsp;	 *               node, while traversing the tree
<i class="no-highlight">317</i>&nbsp;	 */
<i class="no-highlight">318</i>&nbsp;	@Override
<i class="no-highlight">319</i>&nbsp;	public void traversePreOrder(TraversalAction&lt;TreeNode&lt;T&gt;&gt; action) {
<b class="nc"><i class="no-highlight">320</i>&nbsp;		if (!action.isCompleted()) {</b>
<b class="nc"><i class="no-highlight">321</i>&nbsp;			action.perform(this);</b>
<b class="nc"><i class="no-highlight">322</i>&nbsp;			if (!isLeaf()) {</b>
<b class="nc"><i class="no-highlight">323</i>&nbsp;				LinkedMultiTreeNode&lt;T&gt; nextNode = leftMostNode;</b>
<b class="nc"><i class="no-highlight">324</i>&nbsp;				while (nextNode != null) {</b>
<b class="nc"><i class="no-highlight">325</i>&nbsp;					nextNode.traversePreOrder(action);</b>
<b class="nc"><i class="no-highlight">326</i>&nbsp;					nextNode = nextNode.rightSiblingNode;</b>
<i class="no-highlight">327</i>&nbsp;				}
<i class="no-highlight">328</i>&nbsp;			}
<i class="no-highlight">329</i>&nbsp;		}
<i class="no-highlight">330</i>&nbsp;	}
<i class="no-highlight">331</i>&nbsp;
<i class="no-highlight">332</i>&nbsp;	/**
<i class="no-highlight">333</i>&nbsp;	 * Traverses the tree in a post ordered manner starting from the
<i class="no-highlight">334</i>&nbsp;	 * current tree node and performs the traversal action on each
<i class="no-highlight">335</i>&nbsp;	 * traversed tree node
<i class="no-highlight">336</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">337</i>&nbsp;	 * Overridden to have a faster array implementation
<i class="no-highlight">338</i>&nbsp;	 *
<i class="no-highlight">339</i>&nbsp;	 * @param action action, which is to be performed on each tree
<i class="no-highlight">340</i>&nbsp;	 *               node, while traversing the tree
<i class="no-highlight">341</i>&nbsp;	 */
<i class="no-highlight">342</i>&nbsp;	@Override
<i class="no-highlight">343</i>&nbsp;	public void traversePostOrder(TraversalAction&lt;TreeNode&lt;T&gt;&gt; action) {
<b class="nc"><i class="no-highlight">344</i>&nbsp;		if (!action.isCompleted()) {</b>
<b class="nc"><i class="no-highlight">345</i>&nbsp;			if (!isLeaf()) {</b>
<b class="nc"><i class="no-highlight">346</i>&nbsp;				LinkedMultiTreeNode&lt;T&gt; nextNode = leftMostNode;</b>
<b class="nc"><i class="no-highlight">347</i>&nbsp;				while (nextNode != null) {</b>
<b class="nc"><i class="no-highlight">348</i>&nbsp;					nextNode.traversePostOrder(action);</b>
<b class="nc"><i class="no-highlight">349</i>&nbsp;					nextNode = nextNode.rightSiblingNode;</b>
<i class="no-highlight">350</i>&nbsp;				}
<i class="no-highlight">351</i>&nbsp;			}
<b class="nc"><i class="no-highlight">352</i>&nbsp;			action.perform(this);</b>
<i class="no-highlight">353</i>&nbsp;		}
<i class="no-highlight">354</i>&nbsp;	}
<i class="no-highlight">355</i>&nbsp;
<i class="no-highlight">356</i>&nbsp;	/**
<i class="no-highlight">357</i>&nbsp;	 * Returns the height of the current tree node, e.g. the number of edges
<i class="no-highlight">358</i>&nbsp;	 * on the longest downward path between that node and a leaf
<i class="no-highlight">359</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">360</i>&nbsp;	 * Overridden to have a faster array implementation
<i class="no-highlight">361</i>&nbsp;	 *
<i class="no-highlight">362</i>&nbsp;	 * @return height of the current tree node, e.g. the number of edges
<i class="no-highlight">363</i>&nbsp;	 * on the longest downward path between that node and a leaf
<i class="no-highlight">364</i>&nbsp;	 */
<i class="no-highlight">365</i>&nbsp;	@Override
<i class="no-highlight">366</i>&nbsp;	public int height() {
<b class="nc"><i class="no-highlight">367</i>&nbsp;		if (isLeaf()) {</b>
<b class="nc"><i class="no-highlight">368</i>&nbsp;			return 0;</b>
<i class="no-highlight">369</i>&nbsp;		}
<b class="nc"><i class="no-highlight">370</i>&nbsp;		int height = 0;</b>
<b class="nc"><i class="no-highlight">371</i>&nbsp;		LinkedMultiTreeNode&lt;T&gt; nextNode = leftMostNode;</b>
<b class="nc"><i class="no-highlight">372</i>&nbsp;		while (nextNode != null) {</b>
<b class="nc"><i class="no-highlight">373</i>&nbsp;			height = Math.max(height, nextNode.height());</b>
<b class="nc"><i class="no-highlight">374</i>&nbsp;			nextNode = nextNode.rightSiblingNode;</b>
<i class="no-highlight">375</i>&nbsp;		}
<b class="nc"><i class="no-highlight">376</i>&nbsp;		return height + 1;</b>
<i class="no-highlight">377</i>&nbsp;	}
<i class="no-highlight">378</i>&nbsp;
<i class="no-highlight">379</i>&nbsp;	/**
<i class="no-highlight">380</i>&nbsp;	 * Returns the collection of nodes, which have the same parent
<i class="no-highlight">381</i>&nbsp;	 * as the current node; {@link Collections#emptyList()} if the current
<i class="no-highlight">382</i>&nbsp;	 * tree node is root or if the current tree node has no subtrees
<i class="no-highlight">383</i>&nbsp;	 * &lt;p&gt;
<i class="no-highlight">384</i>&nbsp;	 * Overridden to have a faster array implementation
<i class="no-highlight">385</i>&nbsp;	 *
<i class="no-highlight">386</i>&nbsp;	 * @return collection of nodes, which have the same parent as
<i class="no-highlight">387</i>&nbsp;	 *         the current node; {@link Collections#emptyList()} if the
<i class="no-highlight">388</i>&nbsp;	 *         current tree node is root or if the current tree node has
<i class="no-highlight">389</i>&nbsp;	 *         no subtrees
<i class="no-highlight">390</i>&nbsp;	 */
<i class="no-highlight">391</i>&nbsp;	@Override
<i class="no-highlight">392</i>&nbsp;	public Collection&lt;? extends MultiTreeNode&lt;T&gt;&gt; siblings() {
<b class="nc"><i class="no-highlight">393</i>&nbsp;		if (isRoot()) {</b>
<b class="nc"><i class="no-highlight">394</i>&nbsp;			String message = String.format(&quot;Unable to find the siblings. The tree node %1$s is root&quot;, root());</b>
<b class="nc"><i class="no-highlight">395</i>&nbsp;			throw new TreeNodeException(message);</b>
<i class="no-highlight">396</i>&nbsp;		}
<b class="nc"><i class="no-highlight">397</i>&nbsp;		LinkedMultiTreeNode&lt;T&gt; firstNode = ((LinkedMultiTreeNode&lt;T&gt;) parent()).leftMostNode;</b>
<b class="nc"><i class="no-highlight">398</i>&nbsp;		if (firstNode.rightSiblingNode == null) {</b>
<b class="nc"><i class="no-highlight">399</i>&nbsp;			return Collections.emptySet();</b>
<i class="no-highlight">400</i>&nbsp;		}
<b class="nc"><i class="no-highlight">401</i>&nbsp;		Collection&lt;MultiTreeNode&lt;T&gt;&gt; siblings = new LinkedHashSet&lt;&gt;();</b>
<b class="nc"><i class="no-highlight">402</i>&nbsp;		LinkedMultiTreeNode&lt;T&gt; nextNode = firstNode;</b>
<b class="nc"><i class="no-highlight">403</i>&nbsp;		while (nextNode != null) {</b>
<b class="nc"><i class="no-highlight">404</i>&nbsp;			if (!nextNode.equals(this)) {</b>
<b class="nc"><i class="no-highlight">405</i>&nbsp;				siblings.add(nextNode);</b>
<i class="no-highlight">406</i>&nbsp;			}
<b class="nc"><i class="no-highlight">407</i>&nbsp;			nextNode = nextNode.rightSiblingNode;</b>
<i class="no-highlight">408</i>&nbsp;		}
<b class="nc"><i class="no-highlight">409</i>&nbsp;		return siblings;</b>
<i class="no-highlight">410</i>&nbsp;	}
<i class="no-highlight">411</i>&nbsp;
<i class="no-highlight">412</i>&nbsp;}
</div>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
        var codeBlock = document.getElementById('sourceCode');

        if (codeBlock) {
            hljs.highlightBlock(codeBlock);
        }
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2021-12-13 00:09</div>
</div>
</body>
</html>
